<template>
  <div class="login-setting">
    <el-form
      ref="userForm"
      :model="userInfo"
      label-width="120px"
      :rules="rules"
      style="margin-left: 120px; margin-top: 30px"
    >
      <el-form-item label="姓名:" prop="username">
        <el-input v-model="userInfo.username" style="width:300px" />
      </el-form-item>
      <el-form-item label="密码:">
        <el-input v-model="userInfo.password" type="password" style="width:300px" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="AddFn">更新</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
import { saveUserDetailById } from '@/api/employess'
import { getUserDetailById } from '@/api/user'
export default {
  data() {
    return {
      userId: this.$route.query.id,
      userInfo: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUserDetailByIda()
  },
  methods: {
    AddFn() {
      this.$refs.userForm.validate(async val => {
        if (!val) return
        await saveUserDetailById(this.userInfo)
        this.$message.success('更新成功')
        this.$router.back()
      })
    },
    async getUserDetailByIda() {
    //   console.log('a')
      const re = await getUserDetailById(this.userId)
      //   console.log('b')
      //   console.log(re)
      this.userInfo = re.data
    }
  }
}
</script>
